/*
 * HorsePart.h
 *
 *  Created on: Sep 18, 2017
 *      Author: gaoyi
 */

#pragma once

#include "Character/Part.h"
#include "Common/DeclareProperty.h"
#include "HorseItem.h"

#include <map>

namespace ProtoBuf
{
	class CharacterHorseInfo;
}

class HorsePart : public Part
{
public:
	HorsePart();
	virtual ~HorsePart();
public:
	typedef std::map<int, HorseItem>	MapHorse;
	DECLARE_PROPERTY_BOOL(IsOpen);										//
	DECLARE_PROPERTY_OBJECT(MapHorse, HorseItemMap);					//map key is horse id
	DECLARE_PROPERTY_INT32(CurHorseId);									//
	DECLARE_PROPERTY_INT32(LastHorseId);									//
public:
	bool Init(Creature *pMaster, uint32_t partType, CharacterDBInfo* pCharacterDB = nullptr);
	bool UnInit();
	void OnExecute(uint16_t nEventID, uint64_t nSrcID, uint8_t bySrcType, void *pContext, int32_t nLen);
	bool OnMsgHandle(uint32_t cmd, const char* data, uint32_t len);
	void OnTimer(uint32_t nTimerId);
	bool SaveDB(CharacterDBInfo& characterDB);
	bool SaveToPB(::ProtoBuf::CharacterHorseInfo& horseInfo);
	int	 CheckLevel();
	//生物登出入口
	virtual void SynLogout();
	virtual bool SynOnLogin(PlayerClientInfo& playerInfo);
public:
	void HandleHorseTimeOut();
	int ActiveHorse(int horseId, int validHour);
	bool MountHorse(int horseId);
	bool DismountHorse();
	void SendHourseInfo();
public:
	void GetHorseInfoHandle(const char* data, uint32_t len);			//
	void ActiveHorseHandle(const char* data, uint32_t len);				//
	void MountHorseHandle(const char* data, uint32_t len);				//
	void DismountHorseHandle(const char* data, uint32_t len);			//
};





